home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume26 / tulp-3.0.3 / part02 < prev    next >
Encoding:
Text File  |  1993-04-15  |  42.2 KB  |  1,390 lines

  1. Newsgroups: comp.sources.unix
  2. From: Christophe.Wolfhugel@univ-lyon1.fr (Chris Wolfhugel)
  3. Subject: v26i161: tulp-3.0.3 - a listserv-like mailing list manager, V3.0.3, Part02/02
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: Christophe.Wolfhugel@univ-lyon1.fr (Chris Wolfhugel)
  8. Posting-Number: Volume 26, Issue 161
  9. Archive-Name: tulp-3.0.3/part02
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 2 (of 2)."
  18. # Contents:  LICENCE l.c lc.c
  19. # Wrapped by vixie@gw.home.vix.com on Thu Apr 15 18:34:03 1993
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'LICENCE' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'LICENCE'\"
  23. else
  24. echo shar: Extracting \"'LICENCE'\" \(12488 characters\)
  25. sed "s/^X//" >'LICENCE' <<'END_OF_FILE'
  26. X
  27. X            GNU GENERAL PUBLIC LICENSE
  28. X             Version 1, February 1989
  29. X
  30. X Copyright (C) 1989 Free Software Foundation, Inc.
  31. X                    675 Mass Ave, Cambridge, MA 02139, USA
  32. X Everyone is permitted to copy and distribute verbatim copies
  33. X of this license document, but changing it is not allowed.
  34. X
  35. X                Preamble
  36. X
  37. X  The license agreements of most software companies try to keep users
  38. at the mercy of those companies.  By contrast, our General Public
  39. License is intended to guarantee your freedom to share and change free
  40. software--to make sure the software is free for all its users.  The
  41. General Public License applies to the Free Software Foundation's
  42. software and to any other program whose authors commit to using it.
  43. You can use it for your programs, too.
  44. X
  45. X  When we speak of free software, we are referring to freedom, not
  46. price.  Specifically, the General Public License is designed to make
  47. sure that you have the freedom to give away or sell copies of free
  48. software, that you receive source code or can get it if you want it,
  49. that you can change the software or use pieces of it in new free
  50. programs; and that you know you can do these things.
  51. X
  52. X  To protect your rights, we need to make restrictions that forbid
  53. anyone to deny you these rights or to ask you to surrender the rights.
  54. These restrictions translate to certain responsibilities for you if you
  55. distribute copies of the software, or if you modify it.
  56. X
  57. X  For example, if you distribute copies of a such a program, whether
  58. gratis or for a fee, you must give the recipients all the rights that
  59. you have.  You must make sure that they, too, receive or can get the
  60. source code.  And you must tell them their rights.
  61. X
  62. X  We protect your rights with two steps: (1) copyright the software, and
  63. X(2) offer you this license which gives you legal permission to copy,
  64. distribute and/or modify the software.
  65. X
  66. X  Also, for each author's protection and ours, we want to make certain
  67. that everyone understands that there is no warranty for this free
  68. software.  If the software is modified by someone else and passed on, we
  69. want its recipients to know that what they have is not the original, so
  70. that any problems introduced by others will not reflect on the original
  71. authors' reputations.
  72. X
  73. X  The precise terms and conditions for copying, distribution and
  74. modification follow.
  75. X
  76. X            GNU GENERAL PUBLIC LICENSE
  77. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  78. X
  79. X  0. This License Agreement applies to any program or other work which
  80. contains a notice placed by the copyright holder saying it may be
  81. distributed under the terms of this General Public License.  The
  82. X"Program", below, refers to any such program or work, and a "work based
  83. on the Program" means either the Program or any work containing the
  84. Program or a portion of it, either verbatim or with modifications.  Each
  85. licensee is addressed as "you".
  86. X
  87. X  1. You may copy and distribute verbatim copies of the Program's source
  88. code as you receive it, in any medium, provided that you conspicuously and
  89. appropriately publish on each copy an appropriate copyright notice and
  90. disclaimer of warranty; keep intact all the notices that refer to this
  91. General Public License and to the absence of any warranty; and give any
  92. other recipients of the Program a copy of this General Public License
  93. along with the Program.  You may charge a fee for the physical act of
  94. transferring a copy.
  95. X
  96. X  2. You may modify your copy or copies of the Program or any portion of
  97. it, and copy and distribute such modifications under the terms of Paragraph
  98. X1 above, provided that you also do the following:
  99. X
  100. X    a) cause the modified files to carry prominent notices stating that
  101. X    you changed the files and the date of any change; and
  102. X
  103. X    b) cause the whole of any work that you distribute or publish, that
  104. X    in whole or in part contains the Program or any part thereof, either
  105. X    with or without modifications, to be licensed at no charge to all
  106. X    third parties under the terms of this General Public License (except
  107. X    that you may choose to grant warranty protection to some or all
  108. X    third parties, at your option).
  109. X
  110. X    c) If the modified program normally reads commands interactively when
  111. X    run, you must cause it, when started running for such interactive use
  112. X    in the simplest and most usual way, to print or display an
  113. X    announcement including an appropriate copyright notice and a notice
  114. X    that there is no warranty (or else, saying that you provide a
  115. X    warranty) and that users may redistribute the program under these
  116. X    conditions, and telling the user how to view a copy of this General
  117. X    Public License.
  118. X
  119. X    d) You may charge a fee for the physical act of transferring a
  120. X    copy, and you may at your option offer warranty protection in
  121. X    exchange for a fee.
  122. X
  123. Mere aggregation of another independent work with the Program (or its
  124. derivative) on a volume of a storage or distribution medium does not bring
  125. the other work under the scope of these terms.
  126. X
  127. X  3. You may copy and distribute the Program (or a portion or derivative of
  128. it, under Paragraph 2) in object code or executable form under the terms of
  129. Paragraphs 1 and 2 above provided that you also do one of the following:
  130. X
  131. X    a) accompany it with the complete corresponding machine-readable
  132. X    source code, which must be distributed under the terms of
  133. X    Paragraphs 1 and 2 above; or,
  134. X
  135. X    b) accompany it with a written offer, valid for at least three
  136. X    years, to give any third party free (except for a nominal charge
  137. X    for the cost of distribution) a complete machine-readable copy of the
  138. X    corresponding source code, to be distributed under the terms of
  139. X    Paragraphs 1 and 2 above; or,
  140. X
  141. X    c) accompany it with the information you received as to where the
  142. X    corresponding source code may be obtained.  (This alternative is
  143. X    allowed only for noncommercial distribution and only if you
  144. X    received the program in object code or executable form alone.)
  145. X
  146. Source code for a work means the preferred form of the work for making
  147. modifications to it.  For an executable file, complete source code means
  148. all the source code for all modules it contains; but, as a special
  149. exception, it need not include source code for modules which are standard
  150. libraries that accompany the operating system on which the executable
  151. file runs, or for standard header files or definitions files that
  152. accompany that operating system.
  153. X
  154. X  4. You may not copy, modify, sublicense, distribute or transfer the
  155. Program except as expressly provided under this General Public License.
  156. Any attempt otherwise to copy, modify, sublicense, distribute or transfer
  157. the Program is void, and will automatically terminate your rights to use
  158. the Program under this License.  However, parties who have received
  159. copies, or rights to use copies, from you under this General Public
  160. License will not have their licenses terminated so long as such parties
  161. remain in full compliance.
  162. X
  163. X  5. By copying, distributing or modifying the Program (or any work based
  164. on the Program) you indicate your acceptance of this license to do so,
  165. and all its terms and conditions.
  166. X
  167. X  6. Each time you redistribute the Program (or any work based on the
  168. Program), the recipient automatically receives a license from the original
  169. licensor to copy, distribute or modify the Program subject to these
  170. terms and conditions.  You may not impose any further restrictions on the
  171. recipients' exercise of the rights granted herein.
  172. X
  173. X  7. The Free Software Foundation may publish revised and/or new versions
  174. of the General Public License from time to time.  Such new versions will
  175. be similar in spirit to the present version, but may differ in detail to
  176. address new problems or concerns.
  177. X
  178. XEach version is given a distinguishing version number.  If the Program
  179. specifies a version number of the license which applies to it and "any
  180. later version", you have the option of following the terms and conditions
  181. either of that version or of any later version published by the Free
  182. Software Foundation.  If the Program does not specify a version number of
  183. the license, you may choose any version ever published by the Free Software
  184. XFoundation.
  185. X
  186. X  8. If you wish to incorporate parts of the Program into other free
  187. programs whose distribution conditions are different, write to the author
  188. to ask for permission.  For software which is copyrighted by the Free
  189. Software Foundation, write to the Free Software Foundation; we sometimes
  190. make exceptions for this.  Our decision will be guided by the two goals
  191. of preserving the free status of all derivatives of our free software and
  192. of promoting the sharing and reuse of software generally.
  193. X
  194. X                NO WARRANTY
  195. X
  196. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  197. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  198. OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  199. PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  200. OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  201. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  202. TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  203. PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  204. REPAIR OR CORRECTION.
  205. X
  206. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  207. WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  208. REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  209. INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  210. OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  211. TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  212. YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  213. PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  214. POSSIBILITY OF SUCH DAMAGES.
  215. X
  216. X             END OF TERMS AND CONDITIONS
  217. X
  218. X    Appendix: How to Apply These Terms to Your New Programs
  219. X
  220. X  If you develop a new program, and you want it to be of the greatest
  221. possible use to humanity, the best way to achieve this is to make it
  222. free software which everyone can redistribute and change under these
  223. terms.
  224. X
  225. X  To do so, attach the following notices to the program.  It is safest to
  226. attach them to the start of each source file to most effectively convey
  227. the exclusion of warranty; and each file should have at least the
  228. X"copyright" line and a pointer to where the full notice is found.
  229. X
  230. X    <one line to give the program's name and a brief idea of what it does.>
  231. X    Copyright (C) 19yy  <name of author>
  232. X
  233. X    This program is free software; you can redistribute it and/or modify
  234. X    it under the terms of the GNU General Public License as published by
  235. X    the Free Software Foundation; either version 1, or (at your option)
  236. X    any later version.
  237. X
  238. X    This program is distributed in the hope that it will be useful,
  239. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  240. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  241. X    GNU General Public License for more details.
  242. X
  243. X    You should have received a copy of the GNU General Public License
  244. X    along with this program; if not, write to the Free Software
  245. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  246. X
  247. Also add information on how to contact you by electronic and paper mail.
  248. X
  249. If the program is interactive, make it output a short notice like this
  250. when it starts in an interactive mode:
  251. X
  252. X    Gnomovision version 69, Copyright (C) 19xx name of author
  253. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  254. X    This is free software, and you are welcome to redistribute it
  255. X    under certain conditions; type `show c' for details.
  256. X
  257. The hypothetical commands `show w' and `show c' should show the
  258. appropriate parts of the General Public License.  Of course, the
  259. commands you use may be called something other than `show w' and `show
  260. c'; they could even be mouse-clicks or menu items--whatever suits your
  261. program.
  262. X
  263. You should also get your employer (if you work as a programmer) or your
  264. school, if any, to sign a "copyright disclaimer" for the program, if
  265. necessary.  Here a sample; alter the names:
  266. X
  267. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  268. X  program `Gnomovision' (a program to direct compilers to make passes
  269. X  at assemblers) written by James Hacker.
  270. X
  271. X  <signature of Ty Coon>, 1 April 1989
  272. X  Ty Coon, President of Vice
  273. X
  274. That's all there is to it!
  275. END_OF_FILE
  276. if test 12488 -ne `wc -c <'LICENCE'`; then
  277.     echo shar: \"'LICENCE'\" unpacked with wrong size!
  278. fi
  279. # end of 'LICENCE'
  280. fi
  281. if test -f 'l.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'l.c'\"
  283. else
  284. echo shar: Extracting \"'l.c'\" \(15031 characters\)
  285. sed "s/^X//" >'l.c' <<'END_OF_FILE'
  286. X/*-------------------------------------------------------------------------
  287. X *  Listserv - Unix Mailing List manager (sub-set of FRECP's
  288. X *             Bitnet Listserv tool.
  289. X *
  290. X *  Copyright (C) 1991,1992  Kimmo Suominen, Christophe Wolfhugel
  291. X *
  292. X *  Please read the files COPYRIGHT and AUTHORS for the extended
  293. X *  copyrights refering to this file.
  294. X *
  295. X *  This program is free software; you can redistribute it and/or modify
  296. X *  it under the terms of the GNU General Public License as published by
  297. X *  the Free Software Foundation; either version 1, or (at your option)
  298. X *  any later version.
  299. X *
  300. X *  This program is distributed in the hope that it will be useful,
  301. X *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  302. X *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  303. X *  GNU General Public License for more details.
  304. X *
  305. X *  You should have received a copy of the GNU General Public License
  306. X *  along with this program; if not, write to the Free Software
  307. X *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  308. X *----------------------------------------------------------------------*/
  309. X
  310. static char rcsid[] = "@(#)$Id: l.c,v 1.34 93/03/02 22:13:17 wolf Exp $";
  311. X
  312. X#include <stdio.h>
  313. X#include <string.h>
  314. X#include <signal.h>
  315. X#include <time.h>
  316. X#include <unistd.h>
  317. X#include <ctype.h>
  318. X#include <sys/ioctl.h>
  319. X#include <sys/param.h>
  320. X#include <sys/times.h>
  321. X#include <sys/types.h>
  322. X#include <sys/stat.h>
  323. X#include "conf.h"
  324. X#include "ext.h"
  325. X#include "lp.h"
  326. X#include "str.h"
  327. X#include "popen.h"
  328. X#include "ad.h"
  329. X#include "lc.h"
  330. X#include "messages.h"
  331. X#ifdef FAKESYSLOG
  332. X# include "fakesyslog.h"
  333. X#else
  334. X# include <syslog.h>
  335. X#endif
  336. X
  337. int     Debug = 0;
  338. X
  339. short    subj;
  340. X
  341. int    msgHere = 0, done = 0;
  342. char    listName[64];
  343. char    From[MAXLINE], To[MAXLINE], ReplyTo[MAXLINE];
  344. char    buf[MAXLINE], rcpt[MAXLINE];
  345. int    d, h, m, s;
  346. long    startTime, endTime, msgSize;
  347. struct     tms t;
  348. X
  349. static    int ctr;
  350. X
  351. void lTodhms(t)
  352. long t;
  353. X{
  354. X   d = t / ( 24 * 3600L );
  355. X   h = ( t % ( 24 * 3600L )) / 3600;
  356. X   m = ( t % 3600 ) /60;
  357. X   s = t % 60;
  358. X}
  359. X
  360. char *instring(s1, s2)
  361. char *s1, *s2;
  362. X{
  363. X   if ((int)strlen(s2) > (int)strlen(s1)) return(NULL);
  364. X   for (; *(s1 + strlen(s2) - 1); s1++)
  365. X      if (strncasecmp(s1, s2, strlen(s2)) == 0) return(s1);
  366. X   return(NULL);
  367. X}
  368. X
  369. char *strlwr(s)
  370. char *s;
  371. X{
  372. X   char *p = s;
  373. X
  374. X   if (s==NULL) return(NULL);
  375. X   for (; *s; s++) *s = tolower(*s);
  376. X   return(p);
  377. X}
  378. X
  379. char *strupr(s)
  380. char *s;
  381. X{
  382. X   char *p = s;
  383. X
  384. X   if (s == NULL) return(NULL);
  385. X   for (; *s; s++) *s = toupper(*s);
  386. X   return(p);
  387. X}
  388. X
  389. void mailMsg(to, subj)
  390. char *to, *subj;
  391. X{
  392. X   FILE *f, *g;
  393. X   char buf[1024];
  394. X
  395. X   sprintf(buf, "%s %s", SENDMAIL, to);
  396. X   if ((g = l_popen(buf, "w")) == NULL) {
  397. X      syslog(LOG_ERR, "mailMsg - popen failed: %m");
  398. X      exit(2);
  399. X   } /* endif */
  400. X   if ((f = fopen("msg","r")) == NULL) {
  401. X      syslog(LOG_ERR, "mailMsg - fopen failed: %m");
  402. X      exit(2);
  403. X   } /* endif */
  404. X   fprintf(g, "Subject: %s\n\n", subj);
  405. X   while (fgets(buf, sizeof(buf), f) != NULL)
  406. X      fputs(buf, g);
  407. X   l_pclose(g); fclose(f);
  408. X}
  409. X
  410. void sendMsg()
  411. X{
  412. X   char cmd[MAXLINE + 256], *p;
  413. X   int c;
  414. X   FILE *f, *h;
  415. X
  416. X#ifdef ADD_REQUEST
  417. X   sprintf(cmd, "%s -f%s-request %s", SENDMAIL, listName, rcpt);
  418. X#else
  419. X   sprintf(cmd, "%s %s", SENDMAIL, rcpt);
  420. X#endif
  421. X   if ((h = l_popen(cmd,"w")) == NULL) {
  422. X      syslog(LOG_ERR, "sendMsg - popen: %m");
  423. X      exit(2);
  424. X   } /* endif */
  425. X   if ((f = fopen("msg", "r")) == NULL) {
  426. X      syslog(LOG_ERR, "sendMsg - popen: %m");
  427. X      exit(2);
  428. X   } /* endif */
  429. X   while (fgets(buf, sizeof(buf), f) != NULL && buf[0] != '\n') {
  430. X      /* if the line is too long, throw the rest away */
  431. X      if (index(buf, '\n') == NULL) {
  432. X         while ((c = getc(f)) != '\n' && c != EOF)
  433. X            continue;
  434. X      } /* endif */
  435. X      while ((c = getc(f)) == ' ' || c == '\t') {
  436. X     p = &buf[strlen(buf)];
  437. X     *p++ = ' ';
  438. X     if (fgets(p, sizeof(buf) - (p - buf), f) == NULL)
  439. X            break;
  440. X      } /* endwhile */
  441. X      if (!feof(f) && !ferror(f))
  442. X     ungetc(c, f);
  443. X
  444. X      if (strncasecmp(buf, "Status: ", 8) == 0) continue;
  445. X      if (strncasecmp(buf, "X-Envelope-To: ", 15) == 0) continue;
  446. X      if (strncasecmp(buf, "X-Listserv-To: ", 15) == 0) continue;
  447. X      if (strncasecmp(buf, ">From ", 6) == 0) continue;
  448. X      if (strncasecmp(buf, "Return-receipt-to: ", 19) == 0) continue;
  449. X#ifdef STRIP_RECEIVED
  450. X      if (strncasecmp(buf, "Received: ", 10) == 0) continue;
  451. X#endif
  452. X      if (ReplyTo[0] != 0 && strncasecmp(buf, "Reply-To: ", 10) == 0)
  453. X     continue;
  454. X      if (*GetErrorsTo() != '\0' && strncasecmp(buf, "Errors-To: ", 11) == 0)
  455. X     continue;
  456. X#ifdef ADD_SENDER
  457. X      if (strncasecmp(buf, "Sender: ", 8) == 0) continue;
  458. X#endif
  459. X      fputs(buf, h);
  460. X         /* strcpy(cmd, listName); strupr(cmd);
  461. X     fprintf(h, "To: %s Distribution List <%s@%s>\n", cmd, listName, HOST);
  462. X     */
  463. X   } /* endwhile */
  464. X#ifdef ADD_SENDER
  465. X   fputs(versSender, h);
  466. X#endif
  467. X   if (*GetErrorsTo() != '\0') fprintf(h, "Errors-To: %s\n", GetErrorsTo());
  468. X   if (ReplyTo[0] != 0) fprintf(h, "Reply-To: %s\n", ReplyTo);
  469. X   if (subj == 0) fprintf(h, "Subject: <none>\n");
  470. X   if (ctr != 0) fprintf(h, "X-Sequence: %d\n", ctr);
  471. X   do {
  472. X      fputs(buf, h);
  473. X   } while (fgets(buf, sizeof(buf), f) != NULL);
  474. X   fclose(f); l_pclose(h);
  475. X}
  476. X
  477. void saveMsg()
  478. X{
  479. X  FILE *f, *g;
  480. X  long ti;
  481. X  struct tm *t;
  482. X  int dir = 0, oldfile = 0;
  483. X  char cmd[64];
  484. X  struct stat st;
  485. X
  486. X  time(&ti); t = localtime(&ti); f = fopen("msg","r");
  487. X  if (chdir(listName) == -1)
  488. X    return;
  489. X  else {
  490. X    dir = 1;
  491. X    sprintf(cmd, "log%02d%02d", t->tm_year, t->tm_mon + 1);
  492. X    oldfile = stat(cmd, &st) + 1;
  493. X    g = fopen(cmd, "a");
  494. X  } /* endif */
  495. X  if (!oldfile) {
  496. X    fprintf(g, "This digest for list %s has been created on %s\n\n",
  497. X        listName, asctime(t));
  498. X    fputs("------- THIS IS A RFC934 COMPLIANT DIGEST, YOU CAN BURST IT -------\n\n", g);
  499. X  }
  500. X  while (fgets(buf, sizeof(buf), f) != NULL && buf[0] != '\n') {
  501. X    if (strncmp(buf, "Subject:", 8) == 0 || strncmp(buf, "Date:", 5) == 0)
  502. X      fputs(buf, g);
  503. X    if (strncmp(buf, "From:", 5) == 0) {
  504. X      fprintf(g, "From: %s\n", From);
  505. X      if (subj == 0) fprintf(g, "Subject: <none>\n");
  506. X    } /* endif */
  507. X    strlwr(buf);
  508. X  } /* endwhile */
  509. X  if (ctr != 0) fprintf(g, "X-Sequence: %d\n", ctr);
  510. X  do {
  511. X    if (buf[0] == '-') { fprintf(g, "- "); }
  512. X    fputs(buf, g);
  513. X  } while (fgets(buf, 512, f) != NULL);
  514. X  fputs("------- CUT --- CUT --- CUT --- CUT --- CUT --- CUT --- CUT -------\n\n", g);
  515. X  fclose(f); fclose(g);
  516. X  if (dir == 1) chdir(TULPDIR);
  517. X}
  518. X
  519. void fwdMsg()
  520. X{
  521. X   FILE *f, *g, *h;
  522. X   int i;
  523. X   char *p;
  524. X   char cmd[128];
  525. X
  526. X   strcpy(listName, To);
  527. X   if (ReadUserList(listName) == -1) { 
  528. X      syslog(LOG_INFO, "Sending error (list not found)");
  529. X      mailMsg("list-errors", "List-Errors");
  530. X      unlink("msg"); return; 
  531. X   } /* endif */
  532. X   strcpy(buf, GetReplyTo());
  533. X   if (ReplyTo[0] == 0 || instring(buf, ",respect") == NULL) {
  534. X      if (strncasecmp(buf, "list", 4) == 0) {
  535. X         strcpy(cmd, listName);
  536. X         strupr(cmd);
  537. X         sprintf(ReplyTo, "%s Distribution List <%s@%s>", cmd, listName, HOST);
  538. X      } else if (strncasecmp(buf, "sender", 6) != 0)
  539. X         sprintf(ReplyTo, "%s", strtok(buf, ","));
  540. X   } /* endif */
  541. X   RewindUserList();
  542. X   if (strcasecmp(GetSend(), "private") == 0 && !IsUser(From)) {
  543. X      syslog(LOG_INFO,
  544. X         "Mail to list %s from %s - Refused, this user is not allowed",
  545. X         listName, From);
  546. X      sprintf(buf, "%s %s", SENDMAIL, strtok(From, " ")); /* NAK to sender */
  547. X      if ((g = l_popen(buf, "w")) == NULL) {
  548. X     syslog(LOG_ERR, "fwdMsg - popen failed: %m");
  549. X     unlink("msg"); 
  550. X         CloseUserList();
  551. X         return;
  552. X      } /* endif */
  553. X      if ((f = fopen("msg", "r")) == NULL) {
  554. X         syslog(LOG_ERR, "fwdMsg - fopen failed: %m");
  555. X         unlink("msg"); 
  556. X         CloseUserList();
  557. X         return;
  558. X      } /* endif */
  559. X      fprintf(g, TULP_HDRMAILNAK(From, listName));
  560. X      fprintf(g, TULP_MAILPRIVATE);
  561. X      while (fgets(buf, sizeof(buf), f) != NULL)   /* unsent message */
  562. X         fputs(buf, g);
  563. X      l_pclose(g); fclose(f);
  564. X      mailMsg("list-errors", "attempt to send mail by a non subscriber");
  565. X                                            /* to inform list-errors */
  566. X   } else if (strcasecmp(GetSend(), "editor") == 0 && !IsEditor(From)) {
  567. X      syslog(LOG_INFO,"Mail to list %s from %s - Article to moderate",
  568. X                      listName, From);
  569. X      RewindEditorList();
  570. X      if (GetEditor(buf) != NULL) {
  571. X     mailMsg(strtok(buf, " "), "Article to moderate");
  572. X      } /* endif */
  573. X   } else {            /* Ok to send */
  574. X      strcpy(buf, listName);    /* X-Sequence - update listName.n */
  575. X      strcat(buf, ".n");
  576. X      ctr = 0;
  577. X      h = fopen(buf, "r+"); 
  578. X      if (h != NULL) {
  579. X         fscanf(h, "%d", &ctr);
  580. X         rewind(h); fprintf(h, "%d\n", ++ctr); fclose(h);
  581. X      } /* endif */
  582. X      syslog(LOG_INFO,"List %s - Msg from %s accepted", listName, From);
  583. X      saveMsg();        /* save Msg in log file */
  584. X      i = 0; p = rcpt;
  585. X      while (GetUser(buf) != NULL) {
  586. X     strtok(buf, "\t\r\n ");
  587. X     if (((p - rcpt) + strlen(buf)+2) < sizeof(rcpt) && i++ < BATCHSIZE) {
  588. X        sprintf(p, "%s ", buf);
  589. X        p += strlen(p);
  590. X     } else {
  591. X            i = 0; p = rcpt;
  592. X        sendMsg();
  593. X     } /* endif */
  594. X      } /* endwhile */
  595. X      if (i != 0) sendMsg();
  596. X   } /* endif */
  597. X   unlink("msg");
  598. X   CloseUserList();
  599. X}
  600. X
  601. int  copyMail()
  602. X{
  603. X   FILE *h;
  604. X   char *p;
  605. X   int c;
  606. X   struct stat st;
  607. X
  608. X   if (access("msg", 0) == -1) {
  609. X      winInc(); 
  610. X      if ((h = popen(MAILX, "w")) == NULL) return(-1);
  611. X      fprintf(h, "s 1 msg\n");
  612. X      fprintf(h, "q\n");
  613. X      pclose(h);
  614. X   } /* endif */
  615. X   if ((h = fopen("msg", "r")) == NULL) return(-1); 
  616. X   To[0] = 0;
  617. X   fstat(fileno(h), &st); msgSize = st.st_size;
  618. X   subj = 0; To[0] = ReplyTo[0] = 0;
  619. X   while (fgets(buf, sizeof(buf), h) != NULL && buf[0] != '\n') {
  620. X      /* if the line is too long, throw the rest away */
  621. X      if (index(buf, '\n') == NULL) {
  622. X     while ((c = getc(h)) != '\n' && c != EOF)
  623. X        continue;
  624. X      } /* endif */
  625. X      while ((c = getc(h)) == ' ' || c == '\t') {
  626. X     p = &buf[strlen(buf) - 1];
  627. X     *p++ = ' ';
  628. X     if (fgets(p, sizeof(buf) - (p - buf), h) == NULL)
  629. X        break;
  630. X      } /* endif */
  631. X      if (!feof(h) && !ferror(h))
  632. X     ungetc(c, h);
  633. X      strtok(buf, "\n");
  634. X      if (Debug) {
  635. X     fprintf(stderr, "Collected line: %s\n", buf);
  636. X      } /* endif */
  637. X      if (strlen(buf) > MAXLINE) {
  638. X     syslog(LOG_ERR, "Header line too long: %s", strtok(buf, ":"));
  639. X     fclose(h);
  640. X     return(-2);
  641. X      } /* endif */
  642. X      if (strncmp(buf, "Reply-To: ", 10) == 0) {
  643. X         strcpy(ReplyTo, buf + 10);
  644. X      } /* endif */
  645. X      if (strncmp(buf, "Subject: ", 9) == 0) { 
  646. X         /* We could save subject here, but we don't need it */
  647. X         subj = 1; 
  648. X         continue; 
  649. X      } /* endif */
  650. X      if (strncmp(buf, "From: ", 6) == 0) {
  651. X         /* Usually just one author */
  652. X         strcpy(From, buf + 6);
  653. X         continue;
  654. X      } /* endif */
  655. X      if (strncmp(buf, "X-Listserv-To: ", 15) == 0 ) {
  656. X         strcpy(To, buf + 15);
  657. X         continue;
  658. X      } /* endif */
  659. X   } /* endwhile */
  660. X   adChange(From);
  661. X   strlwr(To);
  662. X   fclose(h);
  663. X   if (To[0] == 0) {
  664. X      syslog(LOG_ERR, "Empry X-Listserv-To or not found");
  665. X      return(-2);
  666. X   } /* endif */
  667. X}
  668. X
  669. void sTe()
  670. X{
  671. X   done = 1;
  672. X}
  673. X
  674. X#ifndef NO_SIGUSR1
  675. void sPau()
  676. X{
  677. X   msgHere = 1;
  678. X}
  679. X#endif
  680. X
  681. void main(int argn, char **argv)
  682. X{
  683. X   struct stat st;
  684. X   struct sigaction sa;
  685. X   FILE *f;
  686. X   int i;
  687. X   extern void reapchild();
  688. X
  689. X   while ((i = getopt(argn, argv, "d")) != EOF) {
  690. X      switch (i) {
  691. X     case 'd':
  692. X        Debug = 1;
  693. X        break;
  694. X     default:
  695. X        fprintf(stderr,"usage: %s [-d]\n", *argv);
  696. X        exit(1);
  697. X      } /* endsw */
  698. X   } /* endif */
  699. X   versInit();
  700. X   if (chdir(TULPDIR) == -1) {
  701. X      perror("Can't chdir' to TULPDIR. Aborting.");
  702. X      exit(2);
  703. X   } /* endif */
  704. X   setbuf(stdout, NULL); printf("%s: daemon started for %s\n\r", vers, HOST);
  705. X   printf("Copyright (C) 1991,1992  Kimmo Suominen, Christophe Wolfhugel\n");
  706. X   printf("Listserv comes with ABSOLUTELY NO WARRANTY; for details see\n");
  707. X   printf("the GNU General Public License that is furnished with the\n");
  708. X   printf("sources of this package.\n");
  709. X   if (Debug == 0)
  710. X      if (fork()) exit (0);   /* Dissociate us from tty */
  711. X   times(&t);
  712. X   time(&startTime);
  713. X   nice(NICENESS);
  714. X   if (Debug == 0) {
  715. X      freopen("/dev/null", "w", stdout);
  716. X      freopen("/dev/null", "w", stderr);
  717. X      close(fileno(stdin));
  718. X      setpgrp();
  719. X   } /* endif */
  720. X   sigemptyset(&sa.sa_mask);
  721. X#ifdef SA_RESTART
  722. X   sa.sa_flags = SA_RESTART;    /* Restart system calls?  SA_RESTART */
  723. X                /* Children?  SA_NOCLDWAIT, SA_NOCLDSTOP */
  724. X#else
  725. X   sa.sa_flags = 0;
  726. X#endif
  727. X   sa.sa_handler = sTe;
  728. X   sigaction(SIGTERM, &sa, NULL);
  729. X#ifdef SIGURGENT
  730. X   sigaction(SIGURGENT, &sa, NULL);
  731. X#endif
  732. X   sa.sa_handler = SIG_IGN;
  733. X   /* sa.sa_flags = SA_RESETHAND;    /* Reset to SIG_DFL, not blocked */
  734. X#ifndef NO_SIGUSR1
  735. X   sigaction(SIGUSR1, &sa, NULL);
  736. X#endif
  737. X   sa.sa_handler = reapchild;
  738. X   sigaction(SIGCHLD, &sa, NULL);
  739. X   umask(022);
  740. X   openlog("listserv", LOG_PID, LOG_AUTH);
  741. X   syslog(LOG_INFO, "Listserv Started");
  742. X   f = fopen(PIDFILE, "w");
  743. X   if (f == NULL) {
  744. X      syslog(LOG_ERR, "Can't open PIDFILE for writing. Aborting.");
  745. X      exit(2);
  746. X   } /* endif */
  747. X   fprintf(f, "%d", getpid());
  748. X   fclose(f);
  749. X   umask(077);
  750. X   while (!done) {
  751. X      if (access("msg", 0) == -1 && (stat(MAILFILE, &st) == -1 
  752. X      || st.st_size == 0)) {
  753. X#ifdef NO_SIGUSR1
  754. X         sleep(NO_SIGUSR1);
  755. X#else
  756. X         if (msgHere == 0) {
  757. X       sa.sa_handler = sPau;
  758. X       sigaction(SIGUSR1,&sa,NULL);
  759. X       pause();
  760. X       sa.sa_handler=SIG_IGN;
  761. X       sigaction(SIGUSR1,&sa,NULL);
  762. X     }
  763. X#endif
  764. X         continue;
  765. X      } /* endif */
  766. X      msgHere = 0;
  767. X      if ((i = copyMail()) == -1) continue;
  768. X      if (i == -2) {
  769. X     mailMsg("list-errors", "Unknown error in saveMsg(), see the syslog");
  770. X     unlink("msg");
  771. X     continue;
  772. X      } /* endif */
  773. X      if (instring(From, "mailer") != NULL || 
  774. X      instring(From, "postmaster") != NULL ||
  775. X      instring(From, "listserv") != NULL ||
  776. X      instring(From, "root") != NULL ||
  777. X      instring(From, "system") != NULL ||
  778. X      instring(From, "-request") != NULL ||
  779. X      instring(From, "owner-") != NULL) {
  780. X         syslog(LOG_INFO,"Message from Mailer-Daemon");
  781. X     mailMsg("list-errors", "Trouble");
  782. X         unlink("msg");
  783. X         continue;
  784. X      } /* endif */
  785. X      if (strcmp(To, "listserv") == 0)
  786. X         { listservCmd(); } else { fwdMsg(); }
  787. X   } /* endwhile */
  788. X   syslog(LOG_INFO,"Listserv has been terminated");
  789. X   time(&endTime); lTodhms(endTime-startTime);
  790. X   times(&t);
  791. X   t.tms_utime+=t.tms_cutime;
  792. X   t.tms_stime+=t.tms_cstime;
  793. X   syslog(LOG_INFO,"Total elapsed time: +%dd %02d:%02d:%02d\n",d,h,m,s);
  794. X   lTodhms(t.tms_utime/HZ);
  795. X   syslog(LOG_INFO,"User CPU time:      +%dd %02d:%02d:%02d\n",d,h,m,s);
  796. X   lTodhms(t.tms_stime/HZ);
  797. X   syslog(LOG_INFO,"System CPU time:    +%dd %02d:%02d:%02d\n",d,h,m,s);
  798. X   lTodhms((t.tms_utime+=t.tms_stime)/HZ);
  799. X   syslog(LOG_INFO,"Total CPU time:     +%dd %02d:%02d:%02d\n",d,h,m,s);
  800. X   syslog(LOG_INFO,"%% CPU used:  %02.02f%%\n",
  801. X             (float)(t.tms_utime/HZ*100)/(float)(endTime-startTime+1));
  802. X   closelog();
  803. X   unlink(PIDFILE);
  804. X   exit(0);
  805. X}
  806. END_OF_FILE
  807. if test 15031 -ne `wc -c <'l.c'`; then
  808.     echo shar: \"'l.c'\" unpacked with wrong size!
  809. fi
  810. # end of 'l.c'
  811. fi
  812. if test -f 'lc.c' -a "${1}" != "-c" ; then 
  813.   echo shar: Will not clobber existing file \"'lc.c'\"
  814. else
  815. echo shar: Extracting \"'lc.c'\" \(12273 characters\)
  816. sed "s/^X//" >'lc.c' <<'END_OF_FILE'
  817. X/*-------------------------------------------------------------------------
  818. X *  Listserv - Unix Mailing List manager (sub-set of FRECP's
  819. X *             Bitnet Listserv tool.
  820. X *
  821. X *  Copyright (C) 1991,1992  Kimmo Suominen, Christophe Wolfhugel
  822. X *
  823. X *  Please read the files COPYRIGHT and AUTHORS for the extended
  824. X *  copyrights refering to this file.
  825. X *
  826. X *  This program is free software; you can redistribute it and/or modify
  827. X *  it under the terms of the GNU General Public License as published by
  828. X *  the Free Software Foundation; either version 1, or (at your option)
  829. X *  any later version.
  830. X *
  831. X *  This program is distributed in the hope that it will be useful,
  832. X *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  833. X *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  834. X *  GNU General Public License for more details.
  835. X *
  836. X *  You should have received a copy of the GNU General Public License
  837. X *  along with this program; if not, write to the Free Software
  838. X *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  839. X *----------------------------------------------------------------------*/
  840. X
  841. static char rcsid[] = "@(#)$Id: lc.c,v 1.22 93/03/02 22:40:31 wolf Exp $";
  842. X
  843. X#include <stdio.h>
  844. X#include <string.h>
  845. X#include <unistd.h>
  846. X#include <limits.h>
  847. X#include <sys/param.h>
  848. X#include <sys/types.h>
  849. X#include <signal.h>
  850. X#include <sys/stat.h>
  851. X#include <dirent.h>
  852. X#include <sys/times.h>
  853. X#include "conf.h"
  854. X#include "ext.h"
  855. X#include "l.h"
  856. X#include "lp.h"
  857. X#include "str.h"
  858. X#include "popen.h"
  859. X#include "messages.h"
  860. X#ifdef FAKESYSLOG
  861. X# include "fakesyslog.h"
  862. X#else
  863. X# include <syslog.h>
  864. X#endif
  865. X
  866. XFILE *l;
  867. char adrs[MAXLINE];
  868. static char cmd[MAXLINE + 1];
  869. X
  870. struct kword {
  871. X  char k[4];
  872. X  void (*job)();
  873. X};
  874. X
  875. void help(), list(), review(), subscribe(), signoff(), listindex(),
  876. X     getFile(), addUser(), delUser();
  877. X
  878. struct kword kw[] = { "hel", help,
  879. X                      "lis", list,
  880. X                      "rev", review,
  881. X                      "sub", subscribe,
  882. X                      "sig", signoff,
  883. X                      "uns", signoff,
  884. X                      "ind", listindex,
  885. X                      "get", getFile,
  886. X                      "add", addUser,
  887. X                      "del", delUser,
  888. X                      "",  NULL };
  889. X
  890. X/*
  891. X * Spawn return message MTA
  892. X */
  893. X
  894. XFILE *getMTA(char *recipient)
  895. X{
  896. X  FILE *mta;
  897. X
  898. X#ifdef ADD_REQUEST
  899. X  sprintf(cmd,"%s -flistserv-request %s",SENDMAIL,recipient);
  900. X#else
  901. X  sprintf(cmd,"%s %s",SENDMAIL,recipient);
  902. X#endif
  903. X  mta = l_popen(cmd,"w");
  904. X  fprintf(mta, versFrom);
  905. X#ifdef ADD_SENDER
  906. X  fprintf(mta, versSender);
  907. X#endif
  908. X  return(mta);
  909. X}
  910. X
  911. X/*
  912. X *  HELP
  913. X */
  914. X
  915. void help()
  916. X{
  917. X  FILE *f,*h;
  918. X
  919. X  strlwr(buf);
  920. X  syslog(LOG_INFO,"HELP to %s",From);
  921. X  h=getMTA(adrs);
  922. X  fprintf(h,TULP_HDRHELP(From));
  923. X  f=fopen("helpfile","r");
  924. X  while (fgets(buf, sizeof(buf), f) != NULL)
  925. X    fputs(buf,h);
  926. X  fclose(f);
  927. X  l_pclose(h);
  928. X}
  929. X
  930. X
  931. X/*
  932. X *  LIST
  933. X */
  934. X
  935. void list()
  936. X{
  937. X  FILE *f,*h;
  938. X
  939. X  syslog(LOG_INFO,"LIST to %s",From);
  940. X  h=getMTA(adrs);
  941. X  fprintf(h,TULP_HDRLIST(From));
  942. X  f=fopen("lists","r");
  943. X  while (fgets(buf, sizeof(buf) ,f) != NULL) {
  944. X    if (buf[0] == '#') continue;
  945. X    strtok(buf,",");
  946. X    fprintf(h,"%-15s  * %s\n",buf,strtok(NULL,"\n"));
  947. X  } /* endwhile */
  948. X  fclose(f);
  949. X  l_pclose(h);
  950. X}
  951. X
  952. X
  953. X/*
  954. X *  REVIEW list
  955. X */
  956. X
  957. void review()
  958. X{
  959. X  FILE *h;
  960. X  char *s;
  961. X
  962. X  s=strtok(NULL," \t\n"); strlwr(s);
  963. X  syslog(LOG_INFO,"REV '%s' to %s",s,From);
  964. X  if (s == NULL)
  965. X    fprintf(l,TULP_SYNTAX);
  966. X  else
  967. X    if (ReadUserList(s) == -1)
  968. X      fprintf(l,TULP_NOSUCHLIST);
  969. X    else {
  970. X      h=getMTA(adrs);
  971. X      fprintf(h,TULP_HDRREV(From,s));
  972. X      RewindCommentList();
  973. X      RewindUserList();
  974. X      while (GetComment(buf) != NULL)
  975. X    fprintf(h,"%s\n",buf);
  976. X      if (!IsOwner(From) && (strcasecmp(GetReview(), "owner") == 0
  977. X       || (strcasecmp(GetReview(),"private") == 0 && !IsUser(From))))
  978. X    fprintf(l,TULP_REVPRIVATE);
  979. X      else
  980. X    while (GetUser(buf) != NULL) {
  981. X      strtok(buf,"(");
  982. X      buf[strlen(buf)-1]=0;
  983. X      fprintf(h,"%-40s %s\n",buf,strtok(NULL,")\n"));
  984. X    } /* endwhile */
  985. X      l_pclose(h);
  986. X    } /* endif */
  987. X  CloseUserList();
  988. X}
  989. X
  990. X
  991. X/*
  992. X *  SUBSCRIBE list first last
  993. X */
  994. X
  995. void subscribe()
  996. X{
  997. X  FILE *f,*h;
  998. X  char *s1,*s2;
  999. X
  1000. X  s1=strtok(NULL," \n");
  1001. X  strlwr(s1);
  1002. X  s2=strtok(NULL,"\n");
  1003. X  syslog(LOG_INFO,"SUB '%s' from %s",s1,From);
  1004. X  if (s1 == NULL || s2 == NULL)
  1005. X    fprintf(l,TULP_SYNTAX);
  1006. X  else {
  1007. X    if (ReadUserList(s1) == -1)
  1008. X      fprintf(l,TULP_NOSUCHLIST);
  1009. X    else {
  1010. X      RewindUserList();
  1011. X      RewindOwnerList();
  1012. X      if (strcasecmp(GetSubscription(),"closed") == 0)
  1013. X    fprintf(l,TULP_SUBCLOSED);
  1014. X      else
  1015. X    if (strcasecmp(GetSubscription(),"owner") == 0) {
  1016. X      fprintf(l,TULP_SUBFORWARDED);
  1017. X      rcpt[0]=0;
  1018. X      while (GetOwner(cmd) != NULL) {
  1019. X        strcat(rcpt,strtok(cmd," \t\r\n"));
  1020. X        strcat(rcpt," ");
  1021. X      } /* endwhile */
  1022. X      sprintf(cmd,"%s %s",SENDMAIL,rcpt);
  1023. X      f=l_popen(cmd,"w");
  1024. X      fprintf(f,TULP_SUBREQUEST(adrs,s1,s2));
  1025. X      l_pclose(f);
  1026. X    } else {
  1027. X      sprintf(cmd,"%s (%s)",adrs,s2);
  1028. X      switch (AddUser(cmd)) {
  1029. X      case 0:
  1030. X        h=getMTA(adrs);
  1031. X        fprintf(h,TULP_HDRWELCOME(From,s1));
  1032. X        strcat(s1,".w");
  1033. X        f=fopen(s1,"r");
  1034. X        while (fgets(buf, sizeof(buf), f) != NULL)
  1035. X          fputs(buf,h);
  1036. X        fclose(f);
  1037. X        l_pclose(h);
  1038. X        break;
  1039. X      case 1:
  1040. X        fprintf(l,TULP_SUBALREADY);
  1041. X        break;
  1042. X      } /* endsw */
  1043. X      WriteUserList();
  1044. X    } /* endif */
  1045. X    } /* endif */
  1046. X    CloseUserList();
  1047. X  } /* endif */
  1048. X}
  1049. X
  1050. X
  1051. X/*
  1052. X *  SIGNOFF list
  1053. X */
  1054. X
  1055. void signoff()
  1056. X{
  1057. X  FILE *f;
  1058. X  char *s;
  1059. X
  1060. X  s=strtok(NULL," \t\n");
  1061. X  strlwr(s);
  1062. X  syslog(LOG_INFO,"SIG '%s' from %s",s,From);
  1063. X  if (s == NULL)
  1064. X    fprintf(l,TULP_SYNTAX);
  1065. X  else
  1066. X    if (ReadUserList(s) == -1)
  1067. X      fprintf(l,TULP_NOSUCHLIST);
  1068. X    else {
  1069. X      RewindOwnerList();
  1070. X      rcpt[0]=0;
  1071. X      while (GetOwner(cmd) != NULL) {
  1072. X    strcat(rcpt,strtok(cmd," "));
  1073. X    strcat(rcpt," ");
  1074. X      } /* endwhile */
  1075. X      sprintf(cmd,"%s %s",SENDMAIL,rcpt);
  1076. X      f=l_popen(cmd,"w");
  1077. X      if (DelUser(adrs) == -1) {
  1078. X    fprintf(f,TULP_SIGFAILED(adrs,s));
  1079. X    fprintf(l,TULP_NOTONLIST);
  1080. X      } else {
  1081. X    fprintf(f,TULP_SIGSUCCESS(adrs,s));
  1082. X    fprintf(l,TULP_SIGDONE);
  1083. X      }
  1084. X      l_pclose(f);
  1085. X      WriteUserList();
  1086. X      CloseUserList();
  1087. X    } /* endif */
  1088. X}
  1089. X
  1090. X/*
  1091. X *  INDEX list
  1092. X */
  1093. X
  1094. void listindex()
  1095. X{
  1096. X#define MAX_FILES  640
  1097. X  static char files[MAX_FILES][64+1], swp[64+1];
  1098. X  FILE *h;
  1099. X  char *s;
  1100. X  int i,j,noFiles;
  1101. X  DIR *dirp;
  1102. X  struct dirent *de;
  1103. X  struct stat st;
  1104. X
  1105. X  s=strtok(NULL,"\n");
  1106. X  strlwr(s);
  1107. X  syslog(LOG_INFO,"IND %s from %s",s,From);
  1108. X  if (s == NULL || s[0] == '/' || s[0] == '~' || strstr(s,"..") != NULL)
  1109. X    fprintf(l,TULP_SYNTAX);
  1110. X  else {
  1111. X    if (ReadUserList(s) != -1 && (strcasecmp(GetSend(),"public") != 0
  1112. X     || strcasecmp(GetReview(), "public") != 0)
  1113. X    && !IsUser(From) && !IsOwner(From))
  1114. X      fprintf(l,TULP_NOTONLIST);
  1115. X    else {
  1116. X      if (chdir(s) == -1) fprintf(l,TULP_NONESTORED);
  1117. X      else {
  1118. X    h=getMTA(adrs);
  1119. X    fprintf(h,TULP_HDRINDEX(From,s));
  1120. X    dirp=opendir(".");
  1121. X    noFiles=0;
  1122. X    while (noFiles < MAX_FILES && (de=readdir(dirp)) != NULL)
  1123. X      if (de->d_name[0] != '.')
  1124. X        strcpy(files[noFiles++],de->d_name);
  1125. X    closedir(dirp);
  1126. X    for (i=0; i < noFiles-1; i++) {
  1127. X      for (j=i+1; j < noFiles; j++) {
  1128. X        if (strcmp(files[j],files[i]) < 0) {
  1129. X          strcpy(swp,files[i]);
  1130. X          strcpy(files[i],files[j]);
  1131. X          strcpy(files[j],swp);
  1132. X        } /* endif */
  1133. X      } /* endfor */
  1134. X    } /* endfor */
  1135. X    for (i=0; i < noFiles; i++) {
  1136. X      stat(files[i],&st);
  1137. X      if (st.st_mode & S_IFDIR) strcat(files[i],"/");
  1138. X      fprintf(h,"%-40s %10ld  %s",files[i],st.st_size,ctime(&st.st_mtime));
  1139. X    } /* endif */
  1140. X    chdir(TULPDIR);
  1141. X    if (noFiles == 0) fprintf(l,TULP_INDNOFILES);
  1142. X    l_pclose(h);
  1143. X      } /* endif */
  1144. X    } /* endif */
  1145. X    CloseUserList();
  1146. X  } /* endif */
  1147. X}
  1148. X
  1149. X/*
  1150. X *  GET list file
  1151. X */
  1152. X
  1153. void getFile()
  1154. X{
  1155. X  FILE *f,*h;
  1156. X  char *s,*t;
  1157. X
  1158. X  s=strtok(NULL," ");
  1159. X  t=strtok(NULL," \n");
  1160. X  strlwr(s);
  1161. X  strlwr(t);
  1162. X  syslog(LOG_INFO,"GET %s %s from %s",
  1163. X     (s == NULL) ? " " : s, (t == NULL) ? " " : t, From);
  1164. X  if (ReadUserList(s) != -1 && (strcasecmp(GetSend(),"public") != 0
  1165. X   || strcasecmp(GetReview(), "public") != 0)
  1166. X   && !IsUser(From) && !IsOwner(From))
  1167. X    fprintf(l,TULP_NOTONLIST);
  1168. X  else {
  1169. X    if (chdir(s) == -1) fprintf(l,TULP_NONESTORED);
  1170. X    else {
  1171. X      if (strstr(t,"..") != NULL || *t == '/' || *t == '~') *t=0;
  1172. X      f=fopen(t,"r");
  1173. X      if (f == NULL) fprintf(l,TULP_GETNOSUCHFILE);
  1174. X      else {
  1175. X    h=getMTA(adrs);
  1176. X    fprintf(h,TULP_HDRGET(From,s,t));
  1177. X    while (fgets(buf, sizeof(buf), f) != NULL)
  1178. X      fputs(buf,h);
  1179. X    fclose(f);
  1180. X    l_pclose(h);
  1181. X      } /* endif */
  1182. X      chdir(TULPDIR);
  1183. X    } /* endif */
  1184. X  } /* endif */
  1185. X  CloseUserList();
  1186. X}
  1187. X
  1188. X/*
  1189. X *  ADD list user@host.foo.bar First Last
  1190. X */
  1191. X
  1192. void addUser()
  1193. X{
  1194. X  FILE *f,*h;
  1195. X  char *s,*t,*u;
  1196. X
  1197. X  s=strtok(NULL," \n");
  1198. X  t=strtok(NULL," \n");
  1199. X  u=strtok(NULL,"\n"); 
  1200. X  strlwr(s);
  1201. X  syslog(LOG_INFO,"ADD '%s' %s from %s",s,t,From);
  1202. X  if (s == NULL || t == NULL || u == NULL)
  1203. X    fprintf(l,TULP_SYNTAX);
  1204. X  else
  1205. X    if (ReadUserList(s) == -1)
  1206. X      fprintf(l,TULP_NOSUCHLIST);
  1207. X    else {
  1208. X      RewindUserList();
  1209. X      RewindOwnerList();
  1210. X      if (!IsOwner(From))
  1211. X    fprintf(l,TULP_NOTOWNER);
  1212. X      else {
  1213. X    h=getMTA(t);
  1214. X    sprintf(cmd,"%s (%s)",t,u);
  1215. X    switch (AddUser(cmd)) {
  1216. X    case 0:
  1217. X      fprintf(h,TULP_HDRWELCOME(cmd,s));
  1218. X      fprintf(h,TULP_ADDBY(cmd,s,From));
  1219. X      strcat(s,".w");
  1220. X      f=fopen(s,"r");
  1221. X      while (fgets(buf, sizeof(buf),f) != NULL)
  1222. X        fputs(buf,h);
  1223. X      fclose(f);
  1224. X      fprintf(l,TULP_ADDSUCCESS);
  1225. X      break;
  1226. X    case 1:
  1227. X      fprintf(h,TULP_SUBUPDATED(cmd,s,From));
  1228. X      fprintf(l,TULP_ADDALREADY);
  1229. X      break;
  1230. X    } /* endsw */
  1231. X    l_pclose(h);
  1232. X      } /* endif */
  1233. X      WriteUserList();
  1234. X      CloseUserList();
  1235. X    }
  1236. X}
  1237. X
  1238. X/*
  1239. X *  DELETE list user@host.foo.bar
  1240. X */
  1241. X
  1242. void delUser()
  1243. X{
  1244. X  FILE *h;
  1245. X  char *s1,*s2;
  1246. X
  1247. X  s1=strtok(NULL," \n");
  1248. X  s2=strtok(NULL," \n");
  1249. X  strlwr(s1);
  1250. X  syslog(LOG_INFO,"DEL '%s' %s from %s",s1,s2,From);
  1251. X  if (s1 == NULL || s2 == NULL)
  1252. X    fprintf(l,TULP_SYNTAX);
  1253. X  else
  1254. X    if (ReadUserList(s1) == -1)
  1255. X      fprintf(l,TULP_NOSUCHLIST);
  1256. X    else {
  1257. X      RewindUserList();
  1258. X      RewindOwnerList();
  1259. X      if (!IsOwner(From))
  1260. X    fprintf(l,TULP_NOTOWNER);
  1261. X      else
  1262. X    if (!IsUser(s2))
  1263. X      fprintf(l,TULP_DELNOTONLIST);
  1264. X    else {
  1265. X      sprintf(cmd,"%s",s2);
  1266. X      switch (DelUser(cmd)) {
  1267. X      case 0:
  1268. X        h=getMTA(s2);
  1269. X        fprintf(h,TULP_DELREMOVED(s2,s1,From));
  1270. X        l_pclose(h);
  1271. X        fprintf(l,TULP_DELSUCCESS);
  1272. X        break;
  1273. X      case -1:
  1274. X        fprintf(l,TULP_DELINCONSISTENT);
  1275. X        break;
  1276. X      } /* endsw */
  1277. X    } /* endif */
  1278. X      WriteUserList();
  1279. X      CloseUserList();
  1280. X    } /* endif */
  1281. X}
  1282. X
  1283. X
  1284. int doCmd()
  1285. X{
  1286. X  int i;
  1287. X  char s[4];
  1288. X
  1289. X  if (buf[0] == '\n') return(0);
  1290. X  strncpy(s,strtok(buf," "),3);
  1291. X  s[3]='\0';
  1292. X  strlwr(s);
  1293. X  for (i=0; kw[i].k[0] != 0; i++)
  1294. X    if (strncmp(kw[i].k,s,3) == 0) {
  1295. X      kw[i].job();
  1296. X      return(0);
  1297. X    }
  1298. X  return(-1);
  1299. X}
  1300. X
  1301. void listservCmd()
  1302. X{
  1303. X   int done, noCmd;
  1304. X   char cmd[256];
  1305. X   FILE *f;
  1306. X#ifdef CPUTYPE
  1307. X   struct tms t;
  1308. X   long tt;
  1309. X
  1310. X   times(&t); tt=t.tms_stime+t.tms_utime+t.tms_cstime+t.tms_cutime;
  1311. X#endif
  1312. X
  1313. X   noCmd = 0;
  1314. X   done  = 0;
  1315. X   strcpy(adrs, From); strtok(adrs, " ");
  1316. X   l = getMTA(adrs);
  1317. X   fprintf(l, TULP_HDROUTPUT(From));
  1318. X   f = fopen("msg", "r");
  1319. X   buf[0] = 0;
  1320. X   while (fgets(buf, sizeof(buf), f) != NULL && buf[0] != '\n')
  1321. X    buf[0]=0;
  1322. X   if (buf[0] == 0)
  1323. X      fprintf(l, TULP_NOBODY);
  1324. X   else {
  1325. X      while (!done && fgets(buf, sizeof(buf) - 3, f) != NULL) {
  1326. X         if (strncasecmp(buf, "quit", 4) == 0
  1327. X         || strncasecmp(buf, "end", 3) == 0
  1328. X         || strncasecmp(buf, "stop", 4) == 0
  1329. X         || buf[0] == '-') {
  1330. X        fprintf(l, "> %s",buf);
  1331. X        fprintf(l, TULP_EXITING);
  1332. X            break;
  1333. X         } /* endif */
  1334. X#ifdef SHUTDOWN
  1335. X         if (strcmp(SHUTDOWN, buf) == 0) {
  1336. X        syslog(LOG_INFO, "Shutdown by %s", From);
  1337. X        done = 1;  /* this is clean */
  1338. X        noCmd++;
  1339. X        continue;
  1340. X         } /* endif */
  1341. X#endif
  1342. X         if (buf[0] != '\n') {
  1343. X         fprintf(l,"> %s",buf);
  1344. X        if (doCmd() == -1)
  1345. X           fprintf(l,TULP_SAYWHAT);
  1346. X        else {
  1347. X           noCmd++;
  1348. X           fprintf(l,TULP_OKAY);
  1349. X        } /* endif */
  1350. X         } /* endif */
  1351. X      } /* endwhile */
  1352. X   } /* endif */
  1353. X   if (noCmd == 0) {
  1354. X      fprintf(l,TULP_NOCOMMANDS);
  1355. X      syslog(LOG_INFO,"no commands from",From);
  1356. X      mailMsg("listman","No commands");
  1357. X   } /* endif */
  1358. X   fclose(f);
  1359. X   unlink("msg");
  1360. X#ifdef CPUTYPE
  1361. X   times(&t);
  1362. X   tt=(t.tms_stime+t.tms_utime+t.tms_cstime+t.tms_cutime)-tt;
  1363. X   fprintf(l,TULP_TOTAL((float)tt/HZ,CPUTYPE));
  1364. X#endif
  1365. X   l_pclose(l);
  1366. X}
  1367. END_OF_FILE
  1368. if test 12273 -ne `wc -c <'lc.c'`; then
  1369.     echo shar: \"'lc.c'\" unpacked with wrong size!
  1370. fi
  1371. # end of 'lc.c'
  1372. fi
  1373. echo shar: End of archive 2 \(of 2\).
  1374. cp /dev/null ark2isdone
  1375. MISSING=""
  1376. for I in 1 2 ; do
  1377.     if test ! -f ark${I}isdone ; then
  1378.     MISSING="${MISSING} ${I}"
  1379.     fi
  1380. done
  1381. if test "${MISSING}" = "" ; then
  1382.     echo You have unpacked both archives.
  1383.     rm -f ark[1-9]isdone
  1384. else
  1385.     echo You still need to unpack the following archives:
  1386.     echo "        " ${MISSING}
  1387. fi
  1388. ##  End of shell archive.
  1389. exit 0
  1390.